<?php
/* @var $this yii\web\View*/

use yii\bootstrap\Html;
use yii\data\Pagination;
use yii\widgets\LinkPager;

$this->title = "分类列表";

$this->params['breadcrumbs'][]=$this->title;

$this->params['breadcrumbs'][] = ['label'=>'添加分类','url'=>['goods-category/add']];


$jscode = <<<TEST
//添加点击事件
$(".expand-current").click(function(){
  
   $(this).toggleClass('glyphicon glyphicon-remove');
   $(this).toggleClass('glyphicon glyphicon-plus');
    
    
   var current_tr = $(this).closest('tr');
   var current_status = current_tr.is(); 
   var current_lft = parseInt(current_tr.attr('data-lft'));
   var current_rgt = parseInt(current_tr.attr('data-rgt'));
   var current_tree = parseInt(current_tr.attr('data-tree'));

    //获取categorys
      $(".categorys tr").each(function(){
            if(current_tree == $(this).attr('data-tree') && $(this).attr('data-lft') > current_lft && $(this).attr('data-rgt') < current_rgt ){
                //if(1=1){
                    //$(this).fadeOut;
                    $(this).fadeToggle();
                    //$(this).hide();
                //}
            }
      });
  
 });

TEST;

$this->registerJs($jscode);

?>

<div class="container">
    <table class="table table-bordered table-hover table-condensed table-striped">
        <tr>
            <th>ID</th>
            <th>分类名称</th>
            <th>简介</th>
            <th>操作</th>
        </tr>
        <tbody class="categorys">
        <?php foreach($models as $model):?>
        <tr data-tree="<?=$model['tree']?>"  data-lft="<?=$model['lft']?>"  data-rgt="<?=$model['rgt']?>">
            <td><?=$model['id']?></td>
            <td><?=str_repeat('－',$model['depth']).$model['name']?></td>
            <td><?=$model['intro']?><span class="float-right expand-current  glyphicon glyphicon-remove"></span></td>
            <td>
                <?=Html::a('编辑',['goods-category/edit','id'=>$model['id']],['class'=>'btn btn-default btn-xs'])?>
                <?=Html::a('删除',['goods-category/del','id'=>$model['id']],['class'=>'btn btn-default  btn-xs'])?>
            </td>
        </tr>
        <?php endforeach;?>
        </tbody>
    </table>
</div>

<?php

/** @var $pager  */
echo LinkPager::widget([
    'pagination'=>$pager,
]);

?>

